package test_junit_merchant.ManageConstruction;


import org.openqa.selenium.By;
import util.BaseDriver;

import java.util.Random;

public class AddConstructionClass extends BaseDriver{

    private static AddConstructionClass instance=new AddConstructionClass();

    private AddConstructionClass(){}
    private String className;

    public static AddConstructionClass getInstance(){
        return instance;
    }


    public void switchMenu() throws InterruptedException {
        driver.findElement(By.linkText("施工管理")).click();
        Thread.sleep(1000);
        driver.findElement(By.linkText("施工设置")).click();
        Thread.sleep(2000);
        driver.findElements(By.linkText("施工管理")).get(1).click();
    }

    public void addClass() throws InterruptedException {
        Thread.sleep(1000);
        driver=driver.switchTo().frame(2);
        driver.findElement(By.cssSelector("button.btn.btn-sm.btn-outline.btn-primary")).click();

        Thread.sleep(1000);
        driver=driver.switchTo().frame(0);
        driver.findElement(By.id("name")).click();
        driver.findElement(By.id("name")).clear();

        Random random=new Random();
        int i1=random.nextInt(26);
        int i2=random.nextInt(26);
        className=(char)('a'+i1)+"-"+(char) ('a'+i2)+"";

        driver.findElement(By.id("name")).sendKeys(className);
        driver.findElement(By.id("seq")).click();
        driver.findElement(By.id("seq")).clear();
        driver.findElement(By.id("seq")).sendKeys("0");


        driver=driver.switchTo().parentFrame();
        driver.findElement(By.linkText("确定")).click();
    }

    public void addProject() throws InterruptedException {
        Thread.sleep(2000);
        driver.findElement(By.xpath("//span[contains(text(),'"+className+"')]")).click();

        Thread.sleep(2000);
        driver.findElement(By.cssSelector("p > button.btn.btn-primary.btn-outline.btn-sm")).click();
        Thread.sleep(1000);
        driver=driver.switchTo().frame(0);
        driver.findElement(By.id("name")).click();
        driver.findElement(By.id("name")).clear();
        driver.findElement(By.id("name")).sendKeys("300");
        driver.findElement(By.id("estimationHour")).click();
        driver.findElement(By.id("estimationHour")).clear();
        driver.findElement(By.id("estimationHour")).sendKeys("222");
        driver.findElement(By.id("priceSolution")).click();
        driver.findElement(By.id("priceSolution")).clear();
        driver.findElement(By.id("priceSolution")).sendKeys("33");
        driver.findElement(By.id("settlementPrice")).click();
        driver.findElement(By.id("settlementPrice")).clear();
        driver.findElement(By.id("settlementPrice")).sendKeys("200");
        driver.findElement(By.xpath("//div[@id='availableShops']/label[2]")).click();
        driver.findElement(By.id("product_summary")).click();
        driver=driver.switchTo().parentFrame();
        driver=driver.switchTo().frame(1);
        Thread.sleep(1000);
        driver.findElement(By.id("44172_anchor")).click();
        driver=driver.switchTo().parentFrame();
        driver.findElement(By.cssSelector("#layui-layer2 > div.layui-layer-btn > a.layui-layer-btn0")).click();
        driver=driver.switchTo().frame(0);
        driver.findElement(By.id("seq")).click();
        driver.findElement(By.id("seq")).clear();
        driver.findElement(By.id("seq")).sendKeys("20");
        driver=driver.switchTo().parentFrame();
        driver.findElement(By.linkText("确定")).click();
    }

    public void deleteProject() throws InterruptedException {
        Thread.sleep(5000);
        driver.findElement(By.name("btSelectItem")).click();
        driver.findElement(By.cssSelector("#operation > p > button.btn.btn-danger.btn-outline.btn-sm")).click();
        Thread.sleep(1000);
        driver.findElement(By.linkText("确定")).click();
    }



}
